import java.util.ArrayList;
import java.util.List;

// 7652413
public class P41 {
	public static boolean isPrime(long n) {
		if (n < 2) {
			return false;
		}
		
		long max = (long) Math.sqrt(n);
		for (long i = 2; i <= max; i++) {
			if (n%i == 0) {
				return false;
			}
		}
		
		return true;
	}
	
	public static void getPermutationList(List<Long> list, String num, String result) {
		
		//System.out.println(result);
		
		if (num.length() == 0) {
			System.out.println(">>>" + result);	
			long x = Long.parseLong(result);
			if (isPrime(x)) {
				list.add(x);
			}
			return;
		}
		
		
		for (int i = 0; i < num.length(); i++) {
			String n = num.substring(i, i + 1);
			//System.out.println("*" + n + ":" + num + ":" + result);
			if (!result.contains(n)) {
				getPermutationList(list, num.replaceAll(n, ""), result + n);
			}
		}		
	}
	
	public static void main(String[] args) {
		List<Long> list = new ArrayList<Long>(0);
		
		String n = "";
		for (int i = 1; i <= 9; i++) {
			n += String.valueOf(i);					
			getPermutationList(list, n, "");
		}
		
		System.out.println();
		System.out.println(list.size());
		long max = 0;
		for (Long l : list) {
			if (max < l) {
				max = l;
			}
		}
		System.out.println(max);
	}
}
